<?php

/*

  Action - Attack	$4

  +$2
  Each other player discards down to 3 cards in his hand.

 */

class Militia extends Card implements iAction, iKingdom, iAttack, iBasic {

    public function __construct() {
        parent::__construct("Militia", 4);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }

    public function getDescription() {
        return array(
            "+$2",
            "Each other player discards down to 3 cards in his hand.");
    }

    public function play(Game $game, $isRealCard) {

        $game->addMoney(new Price(2));
        ScreenDisplay::addScreenMessage($game, true, "get +2$", "gets +2$");

        $game->attack($this);

        $game->setPhase(Phase_Sleep);
        $names = $game->getOtherPlayersNames(true);
        foreach ($names as $name) {
            $playHandOther = $game->getPlayHand($name);
            $playHandSize = sizeof($playHandOther);
            if ($playHandSize > 3) {

                $cards_to_discard = $playHandSize - 3;

                $output = MySocket::GetUserReply($game, Input_ChooseMany, $playHandOther, $cards_to_discard, $cards_to_discard, null, "Choose $cards_to_discard cards to discard", $name, true);
            }
        }

        $game->setPhase(Phase_Sleep);
        //the waiting function
        $users_replies = MySocket::getUsersReplies($game);
        foreach ($users_replies as $name => $output) {

            foreach ($output as $card_name) {
                $game->moveCardFromPileToPile($card_name, PlayHand, DiscardPile, $name);
            }

            ScreenDisplay::addScreenMessage($game, true, "discard " . nicePrint($output), "discards " . sizeof($output) . " cards", $name);

            $game->setPhase(Phase_Sleep, $name);
        }

        $game->cardActionFinished();
        return true;
    }

}

?>
